package com.zxjbyte.yiyi.framework.common.exception;

import com.zxjbyte.yiyi.framework.common.domain.api.IResultCode;
import com.zxjbyte.yiyi.framework.common.domain.api.ResultCode;
import lombok.Getter;

/**
 * 业务异常
 *
 * @Author zhangxingjia
 * @Date 2023/3/7 17:30
 * @Version: 1.0
 */
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 723698548485307278L;

    @Getter
    private final IResultCode resultCode;

    public ServiceException(Throwable throwable) {
        this(ResultCode.FAILURE, throwable);
    }

    public ServiceException(String message) {
        super(message);
        this.resultCode = ResultCode.FAILURE;
    }

    public ServiceException(IResultCode resultCode) {
        super(resultCode.getMessage());
        this.resultCode = resultCode;
    }

    public ServiceException(IResultCode resultCode, Throwable cause) {
        super(cause);
        this.resultCode = resultCode;
    }

    /**
     * 提高性能
     *
     * @return Throwable
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

    public Throwable doFillInStackTrace() {
        return super.fillInStackTrace();
    }
}
